package com.lovedice;

import java.util.List;

import android.app.ListActivity;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.ViewFlipper;

import com.lovedice.util.DiceListAdapter;

public abstract class DiceListConfiguration extends ListActivity {

	private Resources res;
	protected ViewFlipper findViewById;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		res = getResources();
	}
	
	protected void carregarLista(List<String> lista){

		adicionarItemIncluir(lista);
        setListAdapter(new DiceListAdapter(this, R.layout.list_item, lista));

        ListView lv = getListView();
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			view.setBackgroundColor(Color.argb(150, 255, 150, 80));
        	if(position==0) {
        		adicionar();
        	} else {
        		acoesEditarOuExcluir( ((TextView) view.findViewById(R.id.list_item_text_name)).getText().toString() );
        	}
          }
        });
	}
	
	private List<String> adicionarItemIncluir(List<String> lista) {
		lista.add(0, res.getString(R.string.dices_list_item_add));
		return lista;
	}
	
	protected abstract void adicionar();
	protected abstract void acoesEditarOuExcluir(String nome);

}
